package com.tgky.ybzb.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class TimeConvert {


    /**
     * 2020 12 1 3 0 0  格式时间转 LocalDateTime
     *
     * @param paraDatetimeString
     * @return
     */
    public static LocalDateTime makeGetS4AlgOutPutPath(String paraDatetimeString) {


        String[] paraTimeString = paraDatetimeString.split(" ");

        int year = Integer.valueOf(paraTimeString[0]).intValue();
        int month = Integer.valueOf(paraTimeString[1]).intValue();
        int day = Integer.valueOf(paraTimeString[2]).intValue();
        int hour = Integer.valueOf(paraTimeString[3]).intValue();
        int minute = Integer.valueOf(paraTimeString[4]).intValue();
        int second = Integer.valueOf(paraTimeString[5]).intValue();

        LocalDateTime paraLocalDate = LocalDateTime.of(year, month, day, hour, minute, second);

        return paraLocalDate;

    }

    /**
     * LocalDateTime 格式时间转 2020 12 1 3 0 0
     *
     * @param timeString
     * @return
     */
    public static String makeGetS4AlgInPutTimeString(String timeString) {
        String outputDateTime = "";
        try {
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy MM dd HH mm ss");

            Date date = inputFormat.parse(timeString);
            outputDateTime = outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();

        }

        return outputDateTime;

    }


    /**
     * yyyy-MM-dd HH:mm:ss  格式时间转 LocalDateTime
     *
     * @param inputDateTime
     * @return
     */
    public static LocalDateTime convertDataTimeFormat2LocalDateTime(String inputDateTime) {
        DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(inputDateTime, inputFormat);
    }


    /**
     * yyyy-MM-dd HH:mm:ss  格式时间转 yyyyMMddHHmmss
     *
     * @param inputDateTime
     * @return
     */
    public static String convertDataTimeFormat(String inputDateTime) {
        String outputDateTime = "";
        try {
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMddHHmmss");

            Date date = inputFormat.parse(inputDateTime);
            outputDateTime = outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();

        }
        return outputDateTime;

    }

    /**
     * LocalDateTime 转换成 yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static String convertDateTimeToStr(LocalDateTime dateTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = dateTime.format(formatter);
        return formattedDateTime;
    }

    /**
     * 获取当前不分时区的时间
     * @return
     */
    public static LocalDateTime getCurrentDateTime(){
        LocalDateTime dateTime = LocalDateTime.now();
        return dateTime;
    }
}
